import {reqGetSearchInfo} from '@/api'
//search模块的小仓库
//处理action，可以书写自己的业务逻辑，也可以处理异步
const actions ={
    //获取search模块数据
    async getSearchList({commit},params={}){
        let result = await reqGetSearchInfo(params)
        if(result.code==200){
            commit('GETSEARCHLIST',result.data)
        }
    }
};
//修改state的唯一手段
const mutations ={
    GETSEARCHLIST(state,searchList){
        state.searchList=searchList
    }
};
const state ={
    searchList:{}
};
//理解为计算属性，用于简化仓库数据，让组件获取仓库的数据更加方便
const getters ={
    //当前形参state是当前仓库中的state并非大仓库中的state
    goodsList(state){
        // 假如网络不给力|没网 则应该返回undefined 所以需要加入[]
        return state.searchList.goodsList || []
    },
    attrsList(state){
        return state.searchList.attrsList  || []
    },
    trademarkList(state){
        return state.searchList.trademarkList  || []
    }

};

export default {
    namespaced:true,
    state,
    mutations,
    actions,
    getters
}